<div class="container">
    <div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all form-container">
        <div class="portlet-header ui-widget-header" id="search-post" style="cursor: pointer;">
            <span class="ui-icon ui-icon-circle-arrow-s"></span>
            <a href="javascript:void(0)" class="download_app"> Quản lý tin đăng</a>
        </div>
        <div class="portlet-content" style="display: block;">
            <div class="box-search">
                <div class="width700">
                    <form id="formSearch" class="forms" method="get" action="<?php echo base_url('cp/post/index'); ?>">
                        <table class="searchForm" border="0">
                            <tbody>
                            <tr>
                                <td>Từ khóa</td>
                                <td><input type="text" value="<?php echo @$param['keyword']; ?>" class="field text" name="keyword"></td>
                                <td>Chuyên mục</td>
                                <td><?php $cat = get_category(0);?>
                                    <select name="parent" id="parent" class="select">
                                        <option selected="selected" value="0">===Tất cả===</option>
                                        <?php
                                        foreach($cat as $key=>$val){
                                            if($val['id']==$param['parent']){
                                                echo '<option value="'.$val['id'].'" selected>'.$val['name'].'</option>';
                                            } else {
                                                echo '<option value="'.$val['id'].'">'.$val['name'].'</option>';
                                            }
                                        }
                                        ?>
                                    </select>
                                </td>
                                <td>Từ ngày</td>
                                <td><input type="text" name="fromdate" id="fromdate"> </td>
                            </tr>
                            <tr>
                                <td>Tỉnh thành</td>
                                <td>
                                    <select name="provinder_id" class="select">
                                        <option value="0">Please select...</option>
                                        <option value="100">Toàn quốc</option>
                                        <?php
                                            foreach($provinder as $item){
                                                if($item['id']==$param['provinder']){
                                                    echo "<option value='".$item['id']."' selected='selected'>".$item['name']."</option>";
                                                }else {
                                                    echo "<option value='".$item['id']."'>".$item['name']."</option>";
                                                }
                                            }
                                        ?>
                                    </select>
                                </td>
                                <td>Nhu cầu</td>
                                <td>
                                    <?php
                                    if(!empty($param['parent'])) {
                                        $getSubCat = get_category($param['parent']);
                                    }
                                    ?>
                                    <select name="child" id="child" class="select">
                                    <option value="">Please select...</option>
                                    <?php
                                    if(!empty($param['parent']) && !empty($getSubCat))
                                        foreach($getSubCat as $val){
                                            if($val['id']==$param['child']){
                                                echo '<option value="'.$val['id'].'" selected="selected">'.$val['name'].'</option>';
                                            }else {
                                                echo '<option value="'.$val['id'].'">'.$val['name'].'</option>';
                                            }
                                        }
                                    ?>
                                </select></td>
                                <td>Đến ngày</td>
                                <td><input type="text" name="todate" id="todate"> </td>
                            </tr>
                            <tr>
                                <td colspan="8" align="right"><input type="submit" name="submit" value="Tìm kiếm" > </td>
                            </tr>


                            </tbody></table>


                    </form>
                </div>
                <div class="width300">
                    <a href="javascript:void(0)" class="download_app"> Quản lý tin đăng</a>

                </div>
            </div>

        </div>
    </div>

    <div class="hastable">
        <?php
        if ($this->session->flashdata('result') != ''){
            echo $this->session->flashdata('result');
        }
        ?>
        <?php echo form_open('cp/category/deleteList',"class='pager-form' id='formlist' name='myform'");?>

        <table>
            <thead>
            <tr>
                <th style="border-left:0px;"><input type="checkbox" class="submit" onclick="this.value=check(this.form['id[]'])" value="check_none"></th>
                <th>Tiêu đề</th>
                <th>Chuyên mục</th>
                <th>Ngày đăng</th>
                <th>Ngày sửa</th>
                <th>Người đăng</th>
                <th>Số lượt xem</th>
                <th>Trạng thái</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            <?php if(count($records)){
                foreach($records as $key=>$item){
                    ?>
                <tr>
                    <td class="center" style="border-left:0px;">
                        <input type="checkbox" value="<?php echo $item['id']; ?>" name="id[]" class="checkbox">
                    </td>
                    <td><a href="javascript:void(0)" datafld="<?php echo $item['id']; ?>" class="view" ><?php echo word_limiter($item['name'],10); ?></a></td>
                    <td><?php echo get_category_label($item['cat_id'],true); ?></td>
                    <td><?php echo date('d-m-Y H:i:s',$item['createdTime']); ?></td>
                    <td><?php echo date('d-m-Y H:i:s',$item['modifyTime']); ?></td>
                    <td><?php echo getByUser($item['user_id'],1); ?></td>
                    <td><?php echo $item['hit']; ?></td>
                    <td><?php echo $item['spam'].' | '.$item['badword'].' | '.$item['locked'].' | '.$item['status']; ?></td>
                    <td>
                        <div style="margin: 0 auto;">
                            <a class="btn_no_text btn ui-state-default ui-corner-all edit" datafld="<?php echo $item['id']; ?>" href="javascript:void(0)">
                                <span class="ui-icon ui-icon-pencil"></span></a>
                            <a class="btn_no_text btn ui-state-default ui-corner-all delete" href="javascript:void(0)" datafld="<?php echo $item['id'] ?>"><span class="ui-icon ui-icon-trash"></span></a>
                        </div></td>

                </tr>
                    <?php } } ?>
            </tbody>
        </table>

        <?php echo form_close();?>
    </div>
    <div class="pagination">
        <?php echo $pagination ?>   </div>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $(".hastable .ui-icon-trash").parent().click(function(){
            if(!confirm("Bạn chắc chắn muốn xóa không?")) {
                return false;
            }
            var id = $(this).attr('datafld');
            jQuery.ajax({
                type: "GET",
                async: false,
                dataType:'json',
                url: base_url + "/category/delete/"+id,
                data: "",
                success: function(data){

                    window.location.reload();
                }
            });
        });

        $(".button .ui-icon-trash").parent().click(function(){
            if($("input:checked").length>0){
                if(!confirm("Bạn chắc chắn muốn xóa không?")) {
                    return false;
                }
                $("#formlist").submit();
            }else{
                alert("Bạn chưa chọn bản nghi để xóa!")

            }
        });

        jQuery('#parent').change(function(){
            var id = $('#parent option:selected').val();
            jQuery.ajax({
                type: "GET",
                async: false,
                dataType:'json',
                url: base_url + "/category/get_subcats/"+id,
                data: "",
                success: function(data){
                    jQuery('#child').html(data['option']);

                }
            });
        });
        jQuery('.edit').click(function(){
            jQuery('#myDialog').dialog('close');
            var datafld = jQuery(this).attr('datafld');
            jQuery.ajax({
                type: "post",
                dataType: "html",
                url: "<?php echo base_url('cp/post/edit'); ?>/"+datafld,
                data: "",
                success: function(data){
                    jQuery('#submitDialog').html(data);
                    $('.ui-dialog-title').html('edit');

                    jQuery('#submitDialog').dialog('open');
                    return false;
                }
            });
        });
        jQuery('.view').click(function(){
            var datafld = jQuery(this).attr('datafld');
            jQuery.ajax({
                type: "post",
                dataType: "html",
                url: "<?php echo base_url('cp/post/detail'); ?>/"+datafld,
                data: "",
                success: function(data){
                    jQuery('#myDialog').html(data);
                    jQuery('#myDialog').dialog('open');
                    return false;
                }
            });
        });
    });
</script>
